package com.example.administrator.basedemos.activity;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.example.administrator.basedemos.dagger2.Component.AppComponent;
import com.example.administrator.basedemos.dagger2.Component.DaggerAppComponent;
import com.example.administrator.basedemos.dagger2.moudle.AppModule;
import com.example.administrator.basedemos.utils.NetWorkUtil;
import com.example.administrator.basedemos.utils.SpUtils;
import com.example.net.RetrofitManger;

/**
 * 创建者     ZCL
 * 创建时间   2016/8/2 15:12
 * 描述	      ${TODO}
 * <p/>
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */

public class MyApplication extends Application {

    private static Context mContext;
    private static Thread  mMainThread;
    private static int     mMainTreadId;
    private static Looper  mMainLooper;
    private static Handler mHandler;
    private static SpUtils mSpUtils;
    private String TAG = "MyApplication";

    //提供appComponent给外界使用
    private   AppComponent mAppComponent;


    public static SpUtils getSpUtils() {
        return mSpUtils;
    }

    @Override
    protected void attachBaseContext (Context base) {
        super.attachBaseContext(base);
    }

    public static Context getContext ( ) {
        return mContext;
    }

    public static long getMainTreadId ( ) {
        return mMainTreadId;
    }

    public static Looper getMainThreadLooper ( ) {
        return mMainLooper;
    }

    public static Handler getHandler ( ) {
        return mHandler;
    }


    @Override
    public void onCreate ( ) {
        super.onCreate( );
        RetrofitManger.init(this);
        NetWorkUtil.init(this);
        // 主线程
        mMainThread = Thread.currentThread( );
        // 主线程Id
        mMainTreadId = android.os.Process.myTid( );
        // tid thread   uid user  pid process
        // 主线程Looper对象
        mMainLooper = getMainLooper( );
        // 定义一个handler
        mHandler = new Handler( );
        mContext = getApplicationContext( );
        mSpUtils = new SpUtils(this);

        mAppComponent= DaggerAppComponent
                .builder()
                .appModule(new AppModule())
                .build();
        // DaggerAppComponent.create();
    }

    public AppComponent getAppComponent(){
        return mAppComponent;
    }

}